using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Cpsc481Phone
{
    public partial class Shell : Form
    {
        public Shell()
        {
            InitializeComponent();
            mainMenu1.Visible = false;
            callHistory1.Visible = false;
            phoneBook1.Visible = false;
            messaging1.Visible = false;
            calendar1.Visible = false;
            lastOutgoingCall1.Visible = false;
            missedEvent1.Visible = false;
            connecting_hank1.Visible = false;
            hank_connected1.Visible = false;
            disconnect_hank1.Visible = false;
            incoming_calls1.Visible = false;
            idleScreen1.Visible = true;
            incoming_john1.Visible = false;
            incomming_11.Visible = false;
            call_john1.Visible = false;
            no_phoneNumber1.Visible = false;
            
        }

        private void button_CONTEXT_LEFT_Click(object sender, EventArgs e)
        {
            if (idleScreen1.Visible == true)
            {
                idleScreen1.Visible = false;
                mainMenu1.reset_currentIndex();
                mainMenu1.Visible = true;
            }else
                if (mainMenu1.Visible == true)
                {
                    mainMenu1.Visible = false;
                    idleScreen1.Visible = true;
                }else
                    if (callHistory1.Visible == true)
                    {
                        mainMenu1.reset_currentIndex();
                        mainMenu1.Visible = true;
                        callHistory1.Visible = false;
                    }else
                        if (phoneBook1.Visible == true)
                        {
                            mainMenu1.reset_currentIndex();
                            mainMenu1.Visible = true;
                            phoneBook1.Visible = false;
                        }else
                            if (messaging1.Visible == true)
                            {
                                mainMenu1.reset_currentIndex();
                                mainMenu1.Visible = true;
                                messaging1.Visible = false;
                            }else
                                if (calendar1.Visible == true)
                                {
                                    mainMenu1.reset_currentIndex();
                                    mainMenu1.Visible = true;
                                    calendar1.Visible = false;
                                }else
                                    if (missedEvent1.Visible == true)
                                    {
                                        idleScreen1.Visible = true;
                                        missedEvent1.Visible = false;
                                    }else
                                        if (incoming_calls1.Visible)
                                        {
                                            callHistory1.Visible = true;
                                            incoming_calls1.Visible = false;
                                        }else
                                            if (incomming_11.Visible)
                                            {
                                                incoming_calls1.Visible = true;
                                                incomming_11.Visible = false;
                                            }else
                                                if (call_john1.Visible)
                                                {
                                                    incoming_calls1.Visible = true;
                                                    call_john1.Visible = false;
                                                }else
                                                    if (no_phoneNumber1.Visible)
                                                    {
                                                        incomming_11.Visible = true;
                                                        no_phoneNumber1.Visible = false;
                                                    }
            

        }

        private void button8_Click(object sender, EventArgs e)
        {
            if (mainMenu1.Visible == true)
            {
                mainMenu1.scroll_down();
            }
            if (missedEvent1.Visible)
            {
                missedEvent1.cursorDown();
            }
            if (incoming_calls1.Visible)
            {
                incoming_calls1.scroll_down();
            }
            if (callHistory1.Visible)
            {
                callHistory1.scroll_down();
            }
        }

        private void button_UP_Click(object sender, EventArgs e)
        {
            if (mainMenu1.Visible == true)
            {
                mainMenu1.scroll_up(); 
            }
            if (missedEvent1.Visible)
            {
                missedEvent1.cursorUp();
            }
            if (callHistory1.Visible)
            {
                callHistory1.scroll_up();
            }
            if (incoming_calls1.Visible)
            {
                incoming_calls1.scroll_up();
            }
        }

        private void button7_Click(object sender, EventArgs e)
        {
            if (mainMenu1.Visible == true)
            {
                mainMenu1.Visible = false;
                idleScreen1.Visible = true;
            }else
                if (callHistory1.Visible == true)
                {
                    idleScreen1.Visible = true;
                    callHistory1.Visible = false;
                }else
                    if (calendar1.Visible == true)
                    {
                        idleScreen1.Visible = true;
                        calendar1.Visible = false;
                    }else
                        if (messaging1.Visible == true)
                        {
                            idleScreen1.Visible = true;
                            messaging1.Visible = false;
                        }else
                            if (phoneBook1.Visible == true)
                            {
                                idleScreen1.Visible = true;
                                phoneBook1.Visible = false;
                            }else
                                if (lastOutgoingCall1.Visible == true)
                                {
                                    idleScreen1.Visible = true;
                                    lastOutgoingCall1.Visible = false;
                                }else
                                    if (missedEvent1.Visible == true)
                                    {
                                        idleScreen1.Visible = true;
                                        missedEvent1.Visible = false;
                                    }else
                                        if (callHistory1.Visible)
                                        {
                                            idleScreen1.Visible = true;
                                            callHistory1.Visible = false;
                                        }else
                                            if (incoming_calls1.Visible)
                                            {
                                                idleScreen1.Visible = true;
                                                incoming_calls1.Visible = false;
                                            }else
                                                if (incomming_11.Visible)
                                                {
                                                    idleScreen1.Visible = true;
                                                    incomming_11.Visible = false;
                                                }
        }

        private void button_CONTEXT_RIGHT_Click(object sender, EventArgs e)
        {
            if (mainMenu1.Visible == true)
            {
                int curr_index = mainMenu1.getListIndex();

                //Call History is selected
                if (curr_index == 0)
                {
                    callHistory1.Visible = true;
                    mainMenu1.Visible = false;
                }else
                    //PhoneBook is selected
                    if (curr_index == 1)
                    {
                        phoneBook1.Visible = true;
                        mainMenu1.Visible = false;
                    }else
                        //Messegaing menu is selected
                        if (curr_index == 2)
                        {
                            messaging1.Visible = true;
                            mainMenu1.Visible = false;
                        }else
                            if (curr_index == 3)
                            {
                                calendar1.Visible = true;
                                mainMenu1.Visible = false;
                            }
            }else
                if (idleScreen1.Visible == true)
                {
                    missedEvent1.Visible = true;
                    idleScreen1.Visible = false;
                }else
                    if (missedEvent1.Visible == true)
                    {
                        
                    }else
                        if (callHistory1.Visible)
                        {
                            int selected_item = callHistory1.getListBox_index();
                            if (selected_item == 0)
                            {
                                incoming_calls1.Visible = true;
                                callHistory1.Visible = false;
                            }
                        }else
                            if (incoming_calls1.Visible)
                            {
                                if (incoming_calls1.getIndex() == 0)
                                {
                                    incomming_11.Visible = true;
                                    incoming_calls1.Visible = false;
                                }else
                                    if (incoming_calls1.getIndex() == 1)
                                    {
                                        incoming_john1.Visible = true;
                                        incoming_calls1.Visible = false;
                                    }
                            }
        }

        private void button_TALK_Click(object sender, EventArgs e)
        {
            //if main screen is displayed and user clicks on talk/call,
            //the last outgoing (last dialed) phone number will be displayed
            //on the screen.
            if (idleScreen1.Visible)
            {
                lastOutgoingCall1.Visible = true;
                idleScreen1.Visible = false;
            }
            else 
                if(lastOutgoingCall1.Visible)
            {
                connecting_hank1.Visible = true;                   
                lastOutgoingCall1.Visible = false;
                timer1.Start();
                timer1.Tick += new EventHandler(Timer_tick);
                hank_connected1.initTime();
                
            }else
                if (incoming_john1.Visible)
                {
                    call_john1.Visible = true;
                    incoming_john1.Visible = false;
                }else
                    if (incomming_11.Visible)
                    {
                        no_phoneNumber1.Visible = true;
                        incomming_11.Visible = false;

                    }
            
        }
        public void Timer_tick(object sender, EventArgs eArgs)
        {
            if (sender == timer1)
            {
                hank_connected1.Visible = true;
                connecting_hank1.Visible = false;
                timer1.Dispose();
            }else
                if (sender == timer2)
                {
                    idleScreen1.Visible = true;
                    disconnect_hank1.Visible = false;
                }
        }

        private void button_END_Click(object sender, EventArgs e)
        {
            if (hank_connected1.Visible)
            {
                disconnect_hank1.setTime(hank_connected1.getTime());
                disconnect_hank1.Visible = true;
                hank_connected1.Visible = false;
                timer2.Start();
                timer2.Tick += new EventHandler(Timer_tick);
            }

        }

        private void button2ABC_Click(object sender, EventArgs e)
        {
            if (messaging1.Visible == true)
            {
                messaging1.clickABC();
            }
        }

        private void button3DEF_Click(object sender, EventArgs e)
        {
            if (messaging1.Visible == true)
            {
                messaging1.clickDEF();
            }
        }






       
        
        
    }
}